/* 
 *	Copyright (C) 2009-2010 miaohua
 *	http://code.google.com/p/lrcshower/
 *
 *  This Program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2, or (at your option)
 *  any later version.
 *   
 *  This Program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *  GNU General Public License for more details.
 *   
 *  You should have received a copy of the GNU General Public License
 *  along with GNU Make; see the file COPYING.  If not, write to
 *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
 *  http://www.gnu.org/copyleft/gpl.html
 *
 */

#pragma once
#include "TypeDef.h"
#include "LayedWinTextRenderBase.h"

#ifndef ULONG_PTR
#define ULONG_PTR unsigned long*
#endif
#include <comdef.h>
#include <gdiplus.h>      
using namespace Gdiplus;  

// Render text on window by gdi plus 
class CGdiplusTextRender: public CLayedWinTextRenderBase
{
public:
    // Construnction
    CGdiplusTextRender();
    virtual ~CGdiplusTextRender();

    // Get the containing box size for LrcLine
    virtual SIZE GetLrcBoxSize(HWND RendWin, const tstring & LrcLine);
    // Before call render,call StartOneLine at first to let render do some initialization
	virtual bool StartOneLine(HWND RendWin, const tstring & Lrc, bool IsNew);
    // Render the text to assigned windows
    virtual bool Render(HWND RendWin, const tstring & Lrc, unsigned int FocusLen);
    // Rend background to assigned windows(only background no text!)
    virtual bool RenderBg(HWND RendWin);
    // Flush the painted buffer to screen
	virtual bool Flush(HWND RendWin, const tstring & Lrc, unsigned int FocusLen, bool IsNew);
private:

    // Helper functions
    // Convert word size from point size to word unit
    float GetWordSize(LONG Height);
    FontStyle GetFontStyle(const LOGFONT* Font);
    // Pre Render to get some gdi+ data
	bool PreRender(HWND RendWin, const tstring & Lrc, bool IsFocus, bool IsCpyData=true, BYTE ** MemBuf = NULL);
	bool PreRender2(HWND RendWin, const tstring & Lrc, bool IsFocus, bool IsCpyData=true, BYTE ** MemBuf = NULL);
    
	// Gdi pulus data member 
    GdiplusStartupInput m_GdiplusStartupInput;
    ULONG_PTR           m_GdiplusToken;
};